﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class News_NewsList : System.Web.UI.Page
{
    PM.PMSys.news thenews = new PM.PMSys.news();
    string type = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["type"] == null)
            {
                type = "notype";
            }
            else
            {
                type = Request.QueryString["type"].ToString().Trim();
            }
            Repeaterdatabind();
            SetDatePicker();
        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Repeaterdatabind();
    }

    //设置日期选择框的属性
    protected void SetDatePicker()
    {
        txtTime1.Attributes.Add("onfocus", "WdatePicker({maxDate:'#F{$dp.$D(\\'"+txtTime2.ClientID+"\\')||\\'2120-10-01\\'}'})");
        txtTime2.Attributes.Add("onfocus", "WdatePicker({minDate:'#F{$dp.$D(\\'"+txtTime1.ClientID+"\\')}',maxDate:'2120-10-01'})");
        
    }

    protected void Repeaterdatabind()
    {
        StringBuilder Sqlstr=new StringBuilder();
        DataTable dt = new DataTable();
        Sqlstr.Append("1=1");
        if (txtTopic.Text.Trim()!="")
        {
            Sqlstr.Append(" and title like '%"+txtTopic.Text.Trim()+"%'");
        }
         if (ddlType.SelectedValue!="")
        {
            Sqlstr.Append(" and type='"+ddlType.SelectedValue.ToString()+"'");
        }
        if (txtTime1.Value.Trim()!=""&&txtTime2.Value.Trim()!="")
        {
            Sqlstr.Append(" and date between '" + txtTime1.Value.Trim() + "' and '" + txtTime2.Value.Trim() + "'");
        }
            switch (type)
            {
                case "declare":
                    dt = thenews.GetList(Sqlstr.ToString()+" and type='申报'", 50, AspNetPager1);
                    break;
                case "approval":
                    dt = thenews.GetList(Sqlstr.ToString()+" and type='评审'", 50, AspNetPager1);
                    break;
                case "others":
                    dt = thenews.GetList(Sqlstr.ToString()+" and type='其他'", 50, AspNetPager1);
                    break;
                case "申报":
                    dt = thenews.GetList(Sqlstr.ToString()+" and type='申报'", 50, AspNetPager1);
                    break;
                case "评审":
                    dt = thenews.GetList(Sqlstr.ToString()+" and type='评审'", 50, AspNetPager1);
                    break;
                case "其他":
                    dt = thenews.GetList(Sqlstr.ToString()+" and type='其他'", 50, AspNetPager1);
                    break;
                default:
                    dt = thenews.GetList(Sqlstr.ToString()+" and 1=1", 50, AspNetPager1);
                    break;
            }
        Repeater1.DataSource = dt;
        Repeater1.DataBind();

    }
    //截取多余字符并高亮显示需要高亮的标题
    static public string strTrim(string str, string hightlight)
    {
        string tmpStr;
        tmpStr = PM.Code.Basic.pmbasic.strCal(str, 60);
        if (hightlight.Equals("1"))
        {
            tmpStr = "<span style=\"color:red;\">" + tmpStr + "</span>";
        }
        return tmpStr;
    }
    //将数据库中的长时间转变成短时间
    static public string ToShortTime(string time)
    {
        string date;
        date = (Convert.ToDateTime(time)).ToShortDateString();
        return date;
    }
    //搜索
    protected void btnSeach_Click(object sender, ImageClickEventArgs e)
    {
        Repeaterdatabind();
    }
}
